from collections import OrderedDict
from urllib.parse import urlencode, quote
import hashlib
import uuid
import time
import hmac


def make_sign(key: str, method: str, path: str, params: dict) -> dict:
    params.update({
        'Timestamp': int(time.time()),
        'SignatureNonce': uuid.uuid4().hex,
    })
    sorted_params = OrderedDict(sorted(params.items(), key=lambda x: x[0]))
    to_sign_str = '{}&{}&{}'.format(method, quote(path, safe=''), urlencode(sorted_params))
    params['Signature'] = hmac.new(key.encode(), to_sign_str.encode(), hashlib.sha1).hexdigest()
    return params
